import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SpaLiseCellData } from "../data/SpaLiseCellData";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class SpaListCellRenderer
    
    export  class SpaListCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            this._numLabel = ObjCreate.createLabel("", 190, 7, 70, 20, flash.text.TextFormatAlign.LEFT, this, true, GlobalStyle.color1Uint);
            this._numLabel.drawNow();
            ObjCreate.createBg(5, 36, 250, 2, this, ImagesConst.SplitLine);
            this._enterBtn = ObjCreate.createGButton("", 10, 3, 170, 26, this);
            this._enterBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onEnterButtonClick);
            this._enterBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            if (arg1) 
            {
                loc1 = arg1 as SpaLiseCellData;
                this._enterBtn.label = Language.getStringByParam(60344, loc1.num);
                this._enterBtn.drawNow();
                this._numLabel.htmlText = this.getDescStrByPlayerNum(loc1.spaInfo.playerNum / loc1.spaInfo.maxNum);
            }
            else 
            {
                this._numLabel.htmlText = "";
            }
            return;
        }

        /* internal  */getDescStrByPlayerNum(arg1: number): string
        {
            if (arg1 < 0.375) 
            {
                return HTMLUtil.addColor(Language.getString(60345), "#22B968");
            }
            if (arg1 < 0.625) 
            {
                return HTMLUtil.addColor(Language.getString(60346), "#EEF2B9");
            }
            if (arg1 < 0.875) 
            {
                return HTMLUtil.addColor(Language.getString(60347), "#F8CF4E");
            }
            return HTMLUtil.addColor(Language.getString(60348), "#F65C60");
        }

        /* internal  */onEnterButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (data) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SpaEnterSpa, (data as SpaLiseCellData).spaInfo.spaId));
            }
            return;
        }

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_numLabel: GLabel;

        /* internal */ /* var */_enterBtn: GButton;
    }
